;
(function(win) {
	var RenderEngine = function() {
		return new RenderEngine.init();
	}

	var renderEngineProps = RenderEngine.prototype;
	RenderEngine.init = function() {};
	RenderEngine.init.prototype = renderEngineProps;
	RenderEngine.version = {};
	RenderEngine.version.number = "1.0.0.RELEASE";
	RenderEngine.version.author = "yumi@omuao.com";
	renderEngineProps.setWorldOptions = function(options) {
		this.worldOptions = options;
	}

	win.RenderEngine = RenderEngine;

	//初始化渲染引擎
	if(win.JadeEngine != null && typeof win.JadeEngine !== "undefined") {
		JadeEngine.World.prototype.setRenderEngine = function(renderEngine) {
			if(!renderEngine instanceof RenderEngine) {
				throw "RenderEngine is not set";
			}
			renderEngine.setWordOptions(this);
			this.renderEngine = renderEngine;
			return this.renderEngine;
		}
		JadeEngine.World.prototype.getRenderEngine = function() {
			if(this.renderEngine == null || typeof this.renderEngine === "undefined") {
				this.renderEngine = new RenderEngine();
				this.renderEngine.setWorldOptions(this);
			}
			return this.renderEngine;
		}
		JadeEngine.World.prototype.getRenderEngineVersionInfo = function() {
			return RenderEngine.version;
		}

		var BitImage = JadeEngine.Graphics2D.BitImage;

		var Point = JadeEngine.Graphics2D.Point;

		var Pixel = JadeEngine.Graphics2D.Pixel;

		var Color = JadeEngine.Graphics2D.Color;

		BitImage.imageDataToBitImage = function(imageData) {
			var image = new BitImage();
			image.width = imageData.width;
			image.height = imageData.height;
			for(var i = 0; i < imageData.height; ++i) {
				for(var j = 0; j < imageData.width; ++j) {
					var x = i * 4 * c.width + 4 * j;
					var r = imageData.data[x];
					var g = imageData.data[x + 1];
					var b = imageData.data[x + 2];
					var a = imageData.data[x + 3];
					var color = new Color(r, g, b, a);
					var point = new Point(j, i);
					var pixel = new Pixel(point, color);
					image.setPixel(pixel);
				}
			}
			return image;
		}

		BitImage.prototype.renderImageData = function(imageData) {
			var b, data, g, i, r, w, x, y, _ref;
			data = imageData.data;
			w = this.width;
			for(y = _ref = this.height - 1; _ref <= 0 ? y < 0 : y > 0; _ref <= 0 ? y++ : y--) {
				for(x = 0; 0 <= w ? x < w : x > w; 0 <= w ? x++ : x--) {
					var pixelColor = this.getPixel(x, y).color;
					i = (x + y * w) * 4;
					b = pixelColor.b;
					g = pixelColor.g;
					r = pixelColor.r;
					data[i++] = r;
					data[i++] = g;
					data[i++] = b;
					data[i++] = pixelColor.a;
				}
			}
		}
	}
}(window));